<template>
  <div v-loading="loading">
    <a-form-model ref="byteDanceForm" :rules="byteDanceRules" :model="byteDanceInfo" :labelCol="{ span: 3 }" :wrapperCol="{ span: 12 }">
      <a-form-model-item label="平台小程序APPID" prop="bytedance_platform_appid">
        <a-input v-model="byteDanceInfo.bytedance_platform_appid" type="text" />
      </a-form-model-item>
      <!-- <a-form-model-item label="商户号" prop="platform_mch_id">
        <a-input v-model="byteDanceInfo.platform_mch_id" type="text" />
      </a-form-model-item> -->
      <a-form-model-item label="平台小程序Secret" prop="bytedance_platform_key">
        <a-input v-model="byteDanceInfo.bytedance_platform_key" type="text" />
      </a-form-model-item>
      <a-form-model-item label="平台小程序Salt" prop="bytedance_platform_salt">
        <a-input v-model="byteDanceInfo.bytedance_platform_salt" type="text" />
      </a-form-model-item>
      <a-form-model-item label="平台小程序Token" prop="bytedance_platform_token">
        <a-input v-model="byteDanceInfo.bytedance_platform_token" type="text" />
      </a-form-model-item>
      <!-- <a-form-model-item label="apiclient_cert" prop="bytedance_platform_apiclient_cert">
        <a-input v-model="byteDanceInfo.bytedance_platform_apiclient_cert" :autoSize="{ minRows: 4, maxRows: 6 }" type="textarea" />
      </a-form-model-item>
      <a-form-model-item label="apiclient_key" prop="bytedance_platform_apiclient_key">
        <a-input v-model="byteDanceInfo.bytedance_platform_apiclient_key" :autoSize="{ minRows: 4, maxRows: 6 }" type="textarea" />
      </a-form-model-item> -->
      <a-form-model-item :wrapper-col="{ span: 12, offset: 2 }">
        <a-button :loading="btnLoading" type="primary" @click="submitForm">
          保存
        </a-button>
      </a-form-model-item>
    </a-form-model>
  </div>
</template>

<script>
import { getPlatformByteDanceSetting, setPlatformByteDanceSetting } from '@/api/saas/setting'

export default {
  name: 'SaasSettingByteDance',
  data () {
    return {
      loading: false,
      btnLoading: false,
      byteDanceInfo: {
        bytedance_platform_appid: '',
        bytedance_platform_mch_id: '',
        bytedance_platform_key: '',
        bytedance_platform_apiclient_cert: '',
        bytedance_platform_apiclient_key: '',
        bytedance_platform_salt: '',
        bytedance_platform_token: ''
      },
      byteDanceRules: {
        bytedance_platform_appid: [{ required: true, message: '请输入平台小程序APPID', trigger: 'blur' }],
        // bytedance_platform_mch_id: [{ required: true, message: '请输入服务商商户号', trigger: 'blur' }],
        bytedance_platform_key: [{ required: true, message: '请输入平台小程序Secret', trigger: 'blur' }],
        bytedance_platform_salt: [{ required: true, message: '请输入平台小程序Salt', trigger: 'blur' }],
        bytedance_platform_token: [{ required: true, message: '请输入平台小程序Token', trigger: 'blur' }]
        // bytedance_platform_apiclient_cert: [{ required: true, message: '请输入服务商apiclient_cert证书', trigger: 'blur' }],
        // bytedance_platform_apiclient_key: [{ required: true, message: '请输入服务商apiclient_key证书', trigger: 'blur' }]
      }
    }
  },
  created () {
    this.getData()
  },
  methods: {
    getData: function () {
      this.loading = true
      getPlatformByteDanceSetting({}).then(res => {
        if (res.code == 0) {
          this.byteDanceInfo = res.data
        }
      }).catch(error => {
        console.log(error)
      }).then(() => {
        this.loading = false
      })
    },
    submitForm: function () {
      this.$refs.byteDanceForm.validate(valid => {
        if (valid) {
          this.btnLoading = true
          setPlatformByteDanceSetting(this.byteDanceInfo).then(res => {
            if (res.code == 0) {
              this.$message.success('保存成功！')
            } else {
              this.$message.warning(res.msg ? res.msg : '保存失败！')
            }
          }).catch(error => {
            console.log(error)
          }).then(() => {
            this.btnLoading = false
          })
        }
      })
    }
  }
}
</script>

<style scoped>

</style>
